//
//  KYweatherModel.m
//  kuaiyi
//
//  Created by 杨亮 on 16/3/10.
//  Copyright © 2016年 kuaiyi. All rights reserved.
//

#import "KYweatherModel.h"
#import "KYNetTool.h"
#import <MJExtension.h>


@implementation KYweatherModel
+(void)weatherWithUrl:(NSString *)url parma:(NSDictionary *)parma successBlock:(void(^)(KYweatherModel *model))successblock failureBlock:(void(^)(NSError *error))failureBlock{
    [[KYNetTool shareManager] GET:url parameters:parma progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *backData = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
        //取到需要的数据
        NSDictionary *data = backData[@"results"][0][@"weather_data"][0];
        //字典转模型
//        NSLog(@"%@",data);
        KYweatherModel *weatherModel = [KYweatherModel mj_objectWithKeyValues:data];
//        NSLog(@"%@",weatherModel);
        successblock(weatherModel);
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        failureBlock(error);
    }];

}

@end
